package com.blink.zookeeper.operate.auth;

import com.blink.zookeeper.ZooKeeperCreator;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.ZooDefs.Ids;
import org.apache.zookeeper.ZooKeeper;

//使用无权限信息的ZooKeeper会话访问含权限信息的数据节点
public class AuthSample_Get {

    final static String PATH = "/zk-book-auth_test";

    public static void main(String[] args) throws Exception {
        ZooKeeper zookeeper1 = ZooKeeperCreator.getZk("zookeeper1");
        zookeeper1.addAuthInfo("digest", "foo:true".getBytes());
        zookeeper1.create(PATH, "init".getBytes(), Ids.CREATOR_ALL_ACL, CreateMode.EPHEMERAL);

        ZooKeeper zookeeper2 = ZooKeeperCreator.getZk("zookeeper2");
        zookeeper2.getData(PATH, false, null);//KeeperException$NoAuthException
    }
}